


import * as echarts from 'echarts'

 export default {
   methods: {
     FunnelChart_V2Init(v){
       const funnlSeries = [
        { value: 60, name: 'Visit' },
        { value: 40, name: 'Inquiry' },
        { value: 20, name: 'Order' },
        { value: 80, name: 'Click' },
        { value: 100, name: 'Show' },
      ]

      let echartEle=  this.$refs[v];
      let myChart = echarts.init(echartEle);

      const {
        dataSourceType,options,staticData
      } = this.controlProperties[v]

      if (dataSourceType === 'static' && Object.keys(staticData).length) {
        options.series = options.series.map((item, index) => {
          return { ...item, data: staticData.series[index].data }
        })
      } else if (dataSourceType === 'static' && !Object.keys(staticData).length){
        options.series = options.series.map((item) => {
          return { ...item, data: funnlSeries }
        })
      }
      options && myChart.setOption(options);
     },
     FunnelChart_V2SetOption(v){
        const { options, flowResult } = this.controlProperties[v]
        let {series } = options
        // series
        series = series.map((item) => {
          item.data = flowResult[item.dataSource[item.dataSource.length - 1].dataKey]
        })
        let echartEle = this.$refs[v];
        let myChart = echarts.init(echartEle);
        options && myChart.setOption(options);
     }
   }
  }
